package com.java110.mall.shop.bmo.couponConf.impl;

import com.java110.mall.shop.bmo.couponConf.IGetCouponConfBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.java110.intf.shop.ICouponConfInnerServiceSMO;
import com.java110.dto.coupon.CouponConfDto;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.List;

@Service("getCouponConfBMOImpl")
public class GetCouponConfBMOImpl implements IGetCouponConfBMO {

    @Autowired
    private ICouponConfInnerServiceSMO couponConfInnerServiceSMOImpl;

    /**
     *
     *
     * @param  couponConfDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(CouponConfDto couponConfDto) {


        int count = couponConfInnerServiceSMOImpl.queryCouponConfsCount(couponConfDto);

        List<CouponConfDto> couponConfDtos = null;
        if (count > 0) {
            couponConfDtos = couponConfInnerServiceSMOImpl.queryCouponConfs(couponConfDto);
        } else {
            couponConfDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) couponConfDto.getRow()), count, couponConfDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
